<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo Yii::$app->name;?> 后台管理</title>
<?php $this->HeaderView(['slide']);?>

<script type="text/javascript" src="<?php echo $this->root_dir; ?>/static/common/js/jquery.tablednd.js"></script>

</head>
<body class="view_form" id="view_form_Model">
<script>
function jointable(action, field){
	var table = $('#joinwith-table-'+action+'-'+field).val();
	var joinfield = $('#joinwith-joinfield-'+action+'-'+field).val();
	var field_val = $('#joinwith-field-'+action+'-'+field).val();
	var content = '<table width="100%" id="join-table">\n\
	<tr>\n\
	<td width="100">关联表</td><td><input type="text" id="table" class="input-text" value="'+table+'"></td>\n\
	</tr>\n\
	<tr>\n\
	<td width="100">关联字段</td><td><input type="text" id="joinfield" class="input-text" value="'+joinfield+'"></td>\n\
	</tr>\n\
	<tr>\n\
	<td>显示字段</td><td><input type="text" id="field" class="input-text" value="'+field_val+'"></td>\n\
	</tr>\n\
	';
	art.dialog({
    content: content,
    id: 'EF893L',
	 button: [
        {
            name: '确定',
            callback: function () {
				var table = $('#join-table #table').val();
				var joinfield = $('#join-table #joinfield').val();
				var field_val = $('#join-table #field').val();
                $('#joinwith-table-'+action+'-'+field).val(table);
				$('#joinwith-joinfield-'+action+'-'+field).val(joinfield);
				$('#joinwith-field-'+action+'-'+field).val(field_val);
				setTimeout(function(){
					return true;
				},500);
                //return false;
            },
            focus: true
        },
        {
            name: '取消'
        }
    ]
});
	
}
</script>

        <form class="view-form-form" method="post" action="<?php echo $this->context->getModelsActionUrl(['api', 'modelid'=>$model->modelid]);?>" enctype="multipart/form-data">
        <input type="hidden" id="catid" name="Models[modelid]" value="<?php echo $model->modelid;?>">
        <input type="hidden" id="type" name="Models[type]" value="<?php echo $model->type;?>">
        <input type="hidden" id="type" name="Models[tablename]" value="<?php echo $model->tablename;?>">
                    <div class="slideTxtBox mtop-0">
        <div class="hd">
                    <ul>
                <li id="list"><a href="javascript:;"><span></span>列表(list)</a></li>
                <li id="view"><a href="javascript:;"><span></span>查看详情(view)</a></li>
                <li id="create"><a href="javascript:;"><span></span>增加(create)</a></li>
                <li id="update"><a href="javascript:;"><span></span>修改(update)</a></li>
                
            </ul>
                </div>
        <div class="bd">
                    <ul class="list">
            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">允许接口调用：</label></th>
                        <td class="td-input">
                        <?php
						

echo submodule\widgets\SubmoduleWidget::widget(['viewPath'=>'switchbutton', 'options' => [
    'primarykey'=> 'modelid',
	'id'=> 'action',
	'name'=> 'Models[api][list][enable]',
	'value'=> @$model->api['list']['enable'],
	'attributes'=> array_merge($model->attributes, array('modelid'=>$model->modelid)),
	'model'=> $model,
	'setting'=> ['defaultvalue'=>0]

]]);
?>
                        
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口编号：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="setting" name="Models[api][list][no]" value="<?php echo @$model->api['list']['no']?>"></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口名称：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="setting" name="Models[api][list][name]" value="<?php echo @$model->api['list']['name']?>"></td>
                    </tr>
                    
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">显示的字段：</label></th>
                        <td class="td-input">
                    <table class="view-index-list" style="width:800px; margin-top:0; margin-bottom:0" border="0" cellspacing="0" cellpadding="0">

    <thead>
                    <tr>
                    <th style="width:150px; text-align:left" align="left">字段</th>
                    <th style="width:70px; text-align:left" align="left">是否显示</th>
                    <th align="left" style="width: auto; text-align:left">CODE</th>
                    </tr>
                    </thead>

                        <?php
						foreach($models['fields'] as $v){
							if (!$v['enabled']) continue;
						?>
                        
                    <tr>
                    <td onclick="jointable('list', '<?php echo $v['field']?>')"><?php echo $v['name']?>(<?php echo $v['field']?>)
                    <input type="text" class="hidden" id="joinwith-joinfield-list-<?php echo $v['field']?>" name="Models[api][list][joinwith][<?php echo $v['field']?>][joinfield]" value="<?php echo @$model->api['list']['joinwith'][$v['field']]['joinfield']?>">
                    <input type="text" class="hidden" id="joinwith-table-list-<?php echo $v['field']?>"  name="Models[api][list][joinwith][<?php echo $v['field']?>][table]" value="<?php echo @$model->api['list']['joinwith'][$v['field']]['table']?>">
                    <input type="text" class="hidden" id="joinwith-field-list-<?php echo $v['field']?>" name="Models[api][list][joinwith][<?php echo $v['field']?>][field]" value="<?php echo @$model->api['list']['joinwith'][$v['field']]['field']?>">
                    
                    </td>
                    <td class="td-locked">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->api['list']['fields']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[api][list][fields][]" <?php echo @in_array($v['field'], $model->api['list']['fields']) ? ' checked' : '';?> />
</td>
                    <td><textarea name="Models[api][function][<?php echo $v['field']?>][list]" class="textarea-text valid" style="width:95%; height:50px;"><?php echo @$model->api['function'][$v['field']]['list']?></textarea></td>
                    </tr>

                        <?php
						}
						?>

                        </table>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">回调方法：</label></th>
                        <td class="td-input"><textarea name="Models[api][function][@callback][list]" class="textarea-text valid" style="width:800px; height:50px;"><?php echo @$model->api['function']['@callback']['list']?></textarea></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口URL：</label></th>
                        <td class="td-input"><?php echo $this->context->apiUrl($model->tablename);?></td>
                    </tr>
                        </tbody>
            </table>
            </ul>
             <ul class="view">
            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">允许接口调用：</label></th>
                        <td class="td-input">
                        <?php
						

echo submodule\widgets\SubmoduleWidget::widget(['viewPath'=>'switchbutton', 'options' => [
    'primarykey'=> 'modelid',
	'id'=> 'action',
	'name'=> 'Models[api][view][enable]',
	'value'=> @$model->api['view']['enable'],
	'attributes'=> array_merge($model->attributes, array('modelid'=>$model->modelid)),
	'model'=> $model,
	'setting'=> ['defaultvalue'=>0]

]]);
?>
                        
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口名称：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="setting" name="Models[api][view][name]" value="<?php echo @$model->api['view']['name']?>"></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">显示的字段：</label></th>
                        <td class="td-input">
                    <table class="view-index-list" style="width:800px; margin-top:0; margin-bottom:0" border="0" cellspacing="0" cellpadding="0">

    <thead>
                    <tr>
                    <th style="width:150px; text-align:left" align="left">字段</th>
                    <th style="width:70px; text-align:left" align="left">是否显示</th>
                    <th align="left" style="width: auto; text-align:left">CODE</th>
                    </tr>
                    </thead>

                        <?php
						foreach($models['fields'] as $v){
							if (!$v['enabled']) continue;
						?>
                        
                    <tr>
                    <td><?php echo $v['name']?>(<?php echo $v['field']?>)</td>
                    <td class="td-locked">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->api['view']['fields']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[api][view][fields][]" <?php echo @in_array($v['field'], $model->api['view']['fields']) ? ' checked' : '';?> />
</td>
                    <td><textarea name="Models[api][function][<?php echo $v['field']?>][view]" class="textarea-text valid" style="width:95%; height:50px;"><?php echo @$model->api['function'][$v['field']]['view']?></textarea></td>
                    </tr>

                        <?php
						}
						?>

                        </table>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">回调方法：</label></th>
                        <td class="td-input"><textarea name="Models[api][function][@callback][view]" class="textarea-text valid" style="width:800px; height:50px;"><?php echo @$model->api['function']['@callback']['view']?></textarea></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口URL：</label></th>
                        <td class="td-input"><?php echo $this->context->apiUrl($model->tablename.'/index/view');?></td>
                    </tr>
                        </tbody>
            </table>
            </ul>
            <ul class="create">
                        <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">允许接口调用：</label></th>
                        <td class="td-input">
                        <?php
						

echo submodule\widgets\SubmoduleWidget::widget(['viewPath'=>'switchbutton', 'options' => [
    'primarykey'=> 'modelid',
	'id'=> 'action',
	'name'=> 'Models[api][create][enable]',
	'value'=> @$model->api['create']['enable'],
	'attributes'=> array_merge($model->attributes, array('modelid'=>$model->modelid)),
	'model'=> $model,
	'setting'=> ['defaultvalue'=>0]

]]);
?>
                        
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口名称：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="setting" name="Models[api][create][name]" value="<?php echo @$model->api['create']['name']?>"></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">接收的字段：</label></th>
                        <td class="td-input">
                    <table class="view-index-list" style="width:800px; margin-top:0; margin-bottom:0" border="0" cellspacing="0" cellpadding="0">

    <thead>
                    <tr>
                    <th style="width:150px; text-align:left" align="left">字段</th>
                    <th style="width:70px; text-align:left" align="left">接口</th>
                    <th style="width:70px; text-align:left" align="left">必传参数</th>
                    <th align="left" style="width: auto; text-align:left">CODE</th>
                    </tr>
                    </thead>

                        <?php
						foreach($models['fields'] as $v){
							if (!$v['enabled']) continue;
						?>
                        
                    <tr>
                    <td><?php echo $v['name']?>(<?php echo $v['field']?>)</td>
                    <td class="td-locked">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->api['create']['fields']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[api][create][fields][]" <?php echo @in_array($v['field'], $model->api['create']['fields']) ? ' checked' : '';?> />
</td>
                    <td class="td-locked">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->api['create']['required']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[api][create][required][]" <?php echo @in_array($v['field'], $model->api['create']['required']) ? ' checked' : '';?> />
</td>
                    <td><textarea name="Models[api][function][<?php echo $v['field']?>][create]" class="textarea-text valid" style="width:95%; height:50px;"><?php echo @$model->api['function'][$v['field']]['create']?></textarea></td>
                    </tr>

                        <?php
						}
						?>

                        </table>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">保存后回调：</label></th>
                        <td class="td-input"><textarea name="Models[api][function][@callback][create]" class="textarea-text valid" style="width:800px; height:50px;"><?php echo @$model->api['function']['@callback']['create']?></textarea></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口URL：</label></th>
                        <td class="td-input"><?php echo $this->context->apiUrl($model->tablename.'/index/create');?></td>
                    </tr>
                        </tbody>
            </table>
            </ul>
             <ul class="update">
                        <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">允许接口调用：</label></th>
                        <td class="td-input">
                        <?php
						

echo submodule\widgets\SubmoduleWidget::widget(['viewPath'=>'switchbutton', 'options' => [
    'primarykey'=> 'modelid',
	'id'=> 'action',
	'name'=> 'Models[api][update][enable]',
	'value'=> @$model->api['update']['enable'],
	'attributes'=> array_merge($model->attributes, array('modelid'=>$model->modelid)),
	'model'=> $model,
	'setting'=> ['defaultvalue'=>0]

]]);
?>
                        
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口名称：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="setting" name="Models[api][update][name]" value="<?php echo @$model->api['update']['name']?>"></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">接收的字段：</label></th>
                        <td class="td-input">
                    <table class="view-index-list" style="width:800px; margin-top:0; margin-bottom:0" border="0" cellspacing="0" cellpadding="0">

    <thead>
                    <tr>
                    <th style="width:150px; text-align:left" align="left">字段</th>
                    <th style="width:70px; text-align:left" align="left">接口</th>
                    <th style="width:70px; text-align:left" align="left">必传参数</th>
                    <th align="left" style="width: auto; text-align:left">CODE</th>
                    </tr>
                    </thead>

                        <?php
						foreach($models['fields'] as $v){
							if (!$v['enabled']) continue;
						?>
                        
                    <tr>
                    <td><?php echo $v['name']?>(<?php echo $v['field']?>)</td>
                    <td class="td-locked">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->api['update']['fields']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[api][update][fields][]" <?php echo @in_array($v['field'], $model->api['update']['fields']) ? ' checked' : '';?> />
</td>
                    <td class="td-locked">
<div onclick="change_switch(this, '');" id="btn-locked" class="locked-<?php echo @in_array($v['field'], $model->api['update']['required']) ? '1' : '0';?>"></div>
<input type="checkbox" class="hidden" value="<?php echo $v['field']?>" name="Models[api][update][required][]" <?php echo @in_array($v['field'], $model->api['update']['required']) ? ' checked' : '';?> />
</td>
                    <td><textarea name="Models[api][function][<?php echo $v['field']?>][update]" class="textarea-text valid" style="width:95%; height:50px;"><?php echo @$model->api['function'][$v['field']]['update']?></textarea></td>
                    </tr>

                        <?php
						}
						?>

                        </table>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">保存后回调：</label></th>
                        <td class="td-input"><textarea name="Models[api][function][@callback][update]" class="textarea-text valid" style="width:800px; height:50px;"><?php echo @$model->api['function']['@callback']['update']?></textarea></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">接口URL：</label></th>
                        <td class="td-input"><?php echo $this->context->apiUrl($model->tablename.'/index/update');?></td>
                    </tr>
                        </tbody>
            </table>
                    </ul>
            
                </div>
    </div>
    <input type="submit" value="提交" name="sbmt" class="btn-submit mt-10" style="margin-left:120px">
<?=$this->csrfToken()?>
    </form>
<script type="text/javascript">

	
jQuery(".slideTxtBox").slide({trigger:"click"});
$(function(){
	$('span.function-fields').click(function(){
		var tab = $('.slideTxtBox .hd li.on').attr('id');
		var field = $(this).prev().children('input').attr('value');
		$('.fields-function', 'ul.'+tab).slideUp(0);
		$('.fields-function-'+field, 'ul.'+tab).slideDown(500);
		$(this).addClass('on').siblings().removeClass('on');
	});
	$(".view-form-form").validate({	
		rules: {
			"Models[name]": {
				required: true,
			},
			"Models[tablename]": {
				required: true,
				remote: {
					url: "<?php echo $this->createUrl(['/models/check-tablename'])?>",     //后台处理程序
					type: "get",               //数据发送方式
					dataType: "json",           //接受数据格式   
					data: {  
					    modelid: '<?php echo $model->modelid?>',                   //要传递的数据
						tablename: function() {
							return $("#tablename").val();
						}
					}
			}
			}
		},
		messages: {
			"Models[name]": {
				required: '请输入模型名称',
			}
		}
	});
    $("#setting-index").tableDnD();	
	
});
</script> 
<?php $this->FooterView();?>
</body>
</html>
